package com.yh.patterns.Iterator;

/**
 * @Auther:云尚学Java
 */
public class Client {
    public static void main(String[] args) {
        //创建聚合对象
        StudentAggregateImpl aggregate=new StudentAggregateImpl();

        //添加元素
        aggregate.addStudent(new Student("云尚","0001"));
        aggregate.addStudent(new Student("tom","0002"));
        aggregate.addStudent(new Student("carry","0003"));
        aggregate.addStudent(new Student("jack","0004"));

        //遍历聚合对象
        //1.获取迭代器对象
        StudentIterator iterator = aggregate.getStudentIterator();
        //2.遍历
        while (iterator.hasNext()){
            //3.获取元素
            Student student = iterator.next();
            System.out.println(student.toString());
        }
    }
}

